<template>
    <d2-container>
        <div slot="header">
            <span style="font-weight: 600;">
                 近即将到期诉讼统计
            </span>
        </div>
        <el-form :inline="true" size="mini" @keyup.enter.native="getLawsuitDueByDays()">
            <el-form-item prop="companyId" label="即将到期天数:">
                <el-select v-model="days" placeholder="请选择">
                    <el-option
                            v-for="item in daysOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button @click="getLawsuitDueByDays()">{{ $t('query') }}</el-button>
            </el-form-item>
            <el-form-item>
                <el-button v-if="$hasPermission('sys:LawsuitStatisticsByNearDate:export')" type="primary" @click="exportExcel()">{{ $t('export')
                    }}
                </el-button>
            </el-form-item>
        </el-form>
        <el-table
                size="mini"
                v-loading="dataListLoading"
                :data="dataList"
                border
                stripe
                style="width: 100%;">
            <el-table-column prop="name" :label="$t('lawsuit.name')" header-align="center" align="center"/>
            <el-table-column prop="lawsuitFlowName" :label="$t('lawsuit.lawsuitFlowName')" header-align="center"
                             align="center"/>
            <el-table-column prop="applyPersonName" :label="$t('lawsuit.applyPersonName')" header-align="center"
                             align="center"/>
            <el-table-column prop="idNumber" :label="$t('lawsuit.idNumber')" header-align="center" align="center"/>
            <el-table-column prop="disputeMoney" :label="$t('lawsuit.disputeMoney')" header-align="center"
                             align="center"/>
            <el-table-column prop="lawsuitFlowTypeName" :label="$t('lawsuit.lawsuitFlowTypeName')" header-align="center"
                             align="center"/>
            <el-table-column prop="flowDeadline" :label="$t('lawsuit.flowDeadline')" header-align="center"
                             align="center" :formatter="dateFormat"/>
            <el-table-column prop="createTime" :label="$t('createTime')" header-align="center" align="center"
                             width="180" :formatter="dateFormat"/>
        </el-table>
        <el-pagination
                slot="footer"
                :current-page="page"
                :page-sizes="[10, 20, 50, 100]"
                :page-size="limit"
                :total="total"
                layout="total, sizes, prev, pager, next, jumper"
                @size-change="pageSizeChangeHandle"
                @current-change="pageCurrentChangeHandle">
        </el-pagination>
    </d2-container>
</template>

<script>

    export default {
        name: "LawsuitStatisticsByNearDate",
        data() {

            return {
                dataList: [],
                companyList: [],
                page: 1, // 当前页码
                limit: 10, // 每页数
                total: 0,
                loading: false,
                dataListLoading: false,
                companyId: '',
                days: '3',
                daysOptions: [{
                    value: '1',
                    label: '近1天'
                }, {
                    value: '2',
                    label: '近2天'
                }, {
                    value: '3',
                    label: '近3天'
                }, {
                    value: '5',
                    label: '近5天'
                }, {
                    value: '7',
                    label: '近7天'
                }],
                columns: [
                    {
                        label: 'ID',
                        prop: 'id'
                    },
                    {
                        label: '诉讼名称',
                        prop: 'name'
                    },
                    {
                        label: '申请人姓名',
                        prop: 'applyPersonName'
                    },
                    {
                        label: '身份证号码',
                        prop: 'idNumber'
                    },
                    {
                        label: '争议金额(元)',
                        prop: 'disputeMoney'
                    },
                    {
                        label: '诉讼流程名称',
                        prop: 'lawsuitFlowTypeName'
                    },
                    {
                        label: '当前流程截止日期',
                        prop: 'flowDeadline'
                    },
                    {
                        label: '创建时间',
                        prop: 'createTime'
                    },
                    {
                        label: '备注',
                        prop: 'remark'
                    }
                ]
            }
        },
        methods: {
            init() {

                this.getLawsuitDueByDays();
            },

            //获取即将到期诉讼数据
            getLawsuitDueByDays: function () {
                let params = {
                    current: this.page,
                    size: this.limit,
                    days: this.days
                };
                this.$http.get('/statistics/getLawsuitDueByDays', params).then(res => {
                    this.dataList = res.records;
                    this.total = res.total;
                }).catch(() => {
                })
            },

            // 分页, 每页条数
            pageSizeChangeHandle(val) {
                this.page = 1;
                this.limit = val;
                this.getLawsuitDueByDays();
            },
            // 分页, 当前页
            pageCurrentChangeHandle(val) {
                this.page = val;
                this.getLawsuitDueByDays();
            },

            remoteMethod(query) {
                if (query !== '') {
                    this.loading = true;
                    this.getCompanyList(query);
                } else {
                    this.companyList = [];
                }
            },

            // 获企业客户所列表
            getCompanyList(queryName) {
                return this.$axios.get('/company/page', {
                    params: {
                        order: 'ASC',
                        orderField: 'createTime',
                        current: 1,
                        size: 20,
                        listMode: true,
                        queryItems: 'name,LIKE,' + queryName
                    }
                }).then(res => {
                    this.loading = false;
                    this.companyList = res.records
                }).catch(() => {
                })
            },

            exportExcel() {
                this.$export.excel({
                    columns: this.columns,
                    data: this.dataList,
                    header: '即将到期诉讼统计',
                    merges: ['A1', 'I1']
                }).then(() => {
                    this.$message({
                        message: '导出表格成功',
                        type: 'success'
                    });
                })
            },

            dateFormat: function (row, column) {
                const dateStr = row[column.property]
                if (dateStr != null) {
                    const dateMat = new Date(dateStr);
                    const year = dateMat.getFullYear();
                    const month = dateMat.getMonth() + 1;
                    const day = dateMat.getDate();
                    const hh = dateMat.getHours();
                    const mm = dateMat.getMinutes();
                    const ss = dateMat.getSeconds();
                    // const timeFormat = year + "-" + month + "-" + day + " " + hh + ":" + mm + ":" + ss;
                    // const timeFormat = year + "-" + month + "-" + day;
                    let timeFormat = year + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day);
                    return timeFormat;
                }
            },

        },
        mounted() {
            this.init();
        }
    }
</script>

<style lang="scss" scoped>
    .inner {
        position: absolute;
        top: 20px;
        right: 20px;
        bottom: 20px;
        left: 20px;
    }

</style>
